//
//  ModelCrowdViewController.m
//  WE
//
//  Created by apple on 15/11/23.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "ModelCrowdViewController.h"
#import "Size.h"
#import "Head.h"
#import "CreatorModel.h"
#import "ToolUtil.h"
#import "DoubleDeckView.h"
#import "RegistrationTableViewCell.h"
#import "SynthesizeTableViewCell.h"
#import "ProvinceTableViewCell.h"
#import "DiseaseViewController.h"
#import "CellAddView.h"

@interface ModelCrowdViewController ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>
{
    UISearchBar *searchBar1;
    UIView *sortView;
    UIView *sortView1;
    DoubleDeckView *doubleView;
    UISegmentedControl *seg;
    CellAddView *cellView;
}
@property (nonatomic,strong) UIVisualEffectView *views;
@end

@implementation ModelCrowdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    seg = [[UISegmentedControl alloc] initWithItems:@[@"科室分类",@"典型人群"]];
    seg.frame = CGRectMake(WindowWidth/4, 7, WindowWidth/2, 30);
    seg.selectedSegmentIndex = 0;
    [seg addTarget:self action:@selector(changeSeg) forControlEvents:UIControlEventValueChanged];
    
    [self.navigationController.navigationBar addSubview:seg];
    
    
    searchBar1 = [[UISearchBar alloc] initWithFrame:CGRectMake(5, 69, WindowWidth - 10, 40)];
    searchBar1.barStyle = UIBarStyleDefault;
    searchBar1.placeholder = @"搜索医院";
    searchBar1.delegate = self;
    [self.view addSubview:searchBar1];
    searchBar1.searchBarStyle = UISearchBarStyleMinimal;

    _views = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _views.frame = CGRectMake(0, 20, WindowWidth, WindowHeight - 20);
    UITapGestureRecognizer *doubleClick = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pressCancle)];
    doubleClick.numberOfTapsRequired = 1;
    [_views addGestureRecognizer:doubleClick];
    _views.hidden = YES;
    
    
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
    cancelButton.frame = CGRectMake(WindowWidth - 60, 20, 50, 40);
    cancelButton.backgroundColor = [UIColor whiteColor];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(pressCancle) forControlEvents:UIControlEventTouchUpInside];
    [_views addSubview:cancelButton];
    [ToolUtil createLine:114 superView:self.view lift:0 width:WindowWidth hight:1 color:[UIColor grayColor]];
    
//    sortView = [CreatorModel initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight - 80) hidden:YES view:self.view];
//    UITapGestureRecognizer*  singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTap)];
//    //点击的次数
//    singleRecognizer.numberOfTapsRequired = 1; // 单击
//    [sortView addGestureRecognizer:singleRecognizer];
//    
        doubleView = [[DoubleDeckView alloc] initWithFrame:CGRectMake(0, 115, WindowWidth, WindowHeight - 115)];
    doubleView.fatherTable.delegate = self;
    doubleView.sonTable.delegate = self;
    doubleView.fatherTable.dataSource = self;
    doubleView.sonTable.dataSource = self;
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(25*Width, 10*Height, 30*Width, 30*Height)];
    imageV.image = [UIImage imageNamed:@"111"];
    
    
    cellView = [[CellAddView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth/2, 50*Height)];
    cellView.label.frame = CGRectMake(70*Width, 0, WindowWidth/2 - 60*Width, 50*Height);
    [cellView addSubview:imageV];
    [self.view addSubview:doubleView];
    

    [self.view addSubview:_views];
    
    
}

- (void)viewWillDisappear:(BOOL)animated{
    [seg removeFromSuperview];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)changeSeg{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)pressCancle{
    
    searchBar1.frame = CGRectMake(5, 69, WindowWidth - 10, 40);
    [self.view addSubview:searchBar1];
    _views.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
    [searchBar1 resignFirstResponder];
    searchBar1.searchBarStyle = UISearchBarStyleMinimal;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == doubleView.fatherTable) {
        UITableViewCell *cell = tableView.visibleCells[indexPath.row];
        cellView.label.text =  @"综合";
        [cell addSubview:cellView];
        
        
        [doubleView.sonTable reloadData];
    }else {
        [self.navigationController pushViewController:[[DiseaseViewController alloc] init] animated:YES];
    }
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (tableView == doubleView.fatherTable) {
        return  1;
    }
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (tableView == doubleView.fatherTable) {
        return 5;
    }
    
    
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == doubleView.fatherTable) {
        static NSString *cellstring = @"SynthesizeTableViewCell";
        SynthesizeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellstring];
        if (!cell) {
            cell = [[SynthesizeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellstring];
            
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor colorWithRed:229/255. green:229/255. blue:229/255. alpha:1.0];
         return cell;
    }else{
    
    
    
    static NSString *cellString = @"RegistrationTableViewCell";
    ProvinceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
    if (!cell) {
        cell = [[ProvinceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString];
    }
        cell.provinceLabel.text = @"什么什么科";
     return cell;
    }
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50*Height;
}


- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    
    self.navigationController.navigationBar.hidden = YES;
    [_views addSubview:searchBar1];
    searchBar.frame = CGRectMake(10, 20, WindowWidth - 70, 40);
    searchBar.searchBarStyle = UISearchBarStyleMinimal;
    _views.hidden = NO;
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
